package com.fifth.emp.controller;

import com.fifth.common.pojo.dto.CommonResult;
import com.fifth.common.pojo.entity.EmpInfo;
import com.fifth.common.pojo.entity.Message;
import com.fifth.emp.service.IMessageService;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 系统通知表 前端控制器
 * </p>
 *
 * @author 徐志豪
 * @since 2022-09-02
 */
@RestController
@RequestMapping("/emp/message")
public class MessageController {

    @Autowired
    private IMessageService messageService;

    /**
     * 发布通知
     * @return
     */
    @PostMapping("/sendMessage")
    public CommonResult sendMessage(@RequestBody Message message){
        //System.out.println("========"+message);
        return messageService.sendMessage(message);
    }

    /**
     * 时间范围分页查询全部
     * @param currentPage
     * @param pageSize
     * @param
     * @param
     * @return
     */
    @PostMapping("/getMessage")
    public CommonResult getMessage(@RequestParam(defaultValue = "1") Integer currentPage, @RequestParam(defaultValue = "5") Integer pageSize, String startTime,String endTime){
        System.out.println(startTime);
        System.out.println("==================="+endTime);
        return messageService.getMessage(currentPage,pageSize,startTime,endTime);
    }

    /**
     * 删除通知
     * @param id
     * @return
     */
    @PostMapping("deleteMessageById/{id}")
    public CommonResult deleteMessageById(@PathVariable String id){
        return messageService.deleteMessageById(id);
    }

    /**
     * 根据公告id 点击操作按钮查看公告信息
     */
    @GetMapping("getMessageById")
    public CommonResult getMessageById(Integer id){
        return messageService.getMessageById(id);
    }


    /**
     * 修改公告信息
     * @param message
     * @return
     */
    @PostMapping("updateMessage")
    public CommonResult updateMessage(@RequestBody Message message){
        return messageService.updateMessage(message);
    }

}
